import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * service 多语言
 * @date: 2018-6-20


 */
import request from 'utils/request';
import { CPAAS_PLATFORM, VERSION_IS_OP } from 'utils/config';
import { isTenantRoleLevel, getCurrentOrganizationId } from 'utils/utils';
var tenantId = getCurrentOrganizationId(); // 多语言层级判断

function promptApi() {
  return isTenantRoleLevel() ? "".concat(tenantId, "/prompts") : "prompts";
}

function api() {
  return VERSION_IS_OP ? "".concat(tenantId, "/prompts") : "prompts";
}
/**
 * 查询语言列表
 * @param {Object} params - 查询参数
 * @param {String} params.page - 页码
 * @param {String} params.size - 页数
 */


export function fetchPromptList(_x) {
  return _fetchPromptList.apply(this, arguments);
}

function _fetchPromptList() {
  _fetchPromptList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(promptApi(), "/page-list"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchPromptList.apply(this, arguments);
}

export function fetchPromptDetail(_x2) {
  return _fetchPromptDetail.apply(this, arguments);
}
/**
 * 新增或更新语言
 * @param {Object} params - 参数
 * @param {String} params.promptKey - 模块代码
 * @param {String} params.promptCode - 代码
 * @param {String} params.lang - 语言名称
 * @param {String} params.description - 描述
 */

function _fetchPromptDetail() {
  _fetchPromptDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(promptApi(), "/detail"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _fetchPromptDetail.apply(this, arguments);
}

export function createPrompt(_x3) {
  return _createPrompt.apply(this, arguments);
}

function _createPrompt() {
  _createPrompt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(promptApi(), "/insert"), {
              method: 'POST',
              body: _objectSpread({}, params)
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _createPrompt.apply(this, arguments);
}

export function updatePrompt(_x4) {
  return _updatePrompt.apply(this, arguments);
}
/**
 * 删除语言
 * @param {Object} params - 参数
 */

function _updatePrompt() {
  _updatePrompt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(promptApi(), "/update"), {
              method: 'PUT',
              body: _objectSpread({}, params)
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _updatePrompt.apply(this, arguments);
}

export function deletePrompt(_x5) {
  return _deletePrompt.apply(this, arguments);
}

function _deletePrompt() {
  _deletePrompt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(promptApi(), "/remove"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _deletePrompt.apply(this, arguments);
}

export function refresh(_x6) {
  return _refresh.apply(this, arguments);
}

function _refresh() {
  _refresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(api(), "/refresh/cache"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _refresh.apply(this, arguments);
}